<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>
<body>
  <script>

    const array = [1, [2, 3, [3.1]], [4, 5], 6];

    function flatten(arr) {
      return arr.reduce((pre, cur) => {
        return pre.concat(Array.isArray(cur) ? flatten(cur) : cur)
      }, [])
    }

    console.log(flatten(array))

  </script>
</body>
</html>